package cn.iocoder.yudao.module.reading.convert.plan;

import cn.iocoder.yudao.module.reading.controller.app.plan.vo.ReadingPlanRespVO;
import cn.iocoder.yudao.module.reading.dal.dataobject.plan.ReadingPlanDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.time.LocalDate;
import java.util.List;

/**
 * 阅读计划 Convert
 *
 * @author 芋道源码
 */
@Mapper
public interface ReadingPlanConvert {

    ReadingPlanConvert INSTANCE = Mappers.getMapper(ReadingPlanConvert.class);

    @Mapping(target = "nextTaskDate", expression = "java(calculateNextTaskDate(bean))")
    ReadingPlanRespVO convert(ReadingPlanDO bean);

    List<ReadingPlanRespVO> convertList(List<ReadingPlanDO> list);

    /**
     * 计算下次任务日期
     */
    default LocalDate calculateNextTaskDate(ReadingPlanDO plan) {
        if (plan.getStartDate() == null) {
            return null;
        }
        // 简单计算：开始日期 + 当前天数
        return plan.getStartDate().plusDays(plan.getCurrentDay());
    }

}
